package thisIsPKQ

import (
	"banzhuan_hb/models"
	"banzhuan_hb/services"
)


//所有线上交易对可组成的三角组合
func GetSchd() ([]models.SchedulingIndex,[]models.SymbolsData) {
	//获取交易所所有交易对
	symbolsReturn:=services.GetSymbols()

	//调度结构体，标记形成三角套利的每一步币种，在所有交易对数组的位置
	schedulingIndex:=models.SchedulingIndex{}
	schedulingIndexArg:=[]models.SchedulingIndex{}
	//log.Println(symbolsReturn.Data[0].Symbol)
	for i:=0;i<len(symbolsReturn.Data) ;i++  {
		//log.Println("====",symbolsReturn.Data[i].State)
		//只要上线的交易对
		if symbolsReturn.Data[i].State=="online" && symbolsReturn.Data[i].SymbolPartition=="main"{
			switch symbolsReturn.Data[i].QuoteCurrency {
			//定四个套利母币，可根据需要调整
			case "usdt","husd","btc","eth":
				//step_1:=symbolsReturn.Data[i].Symbol
				step_1_count:=i
				//获取套利第二步交易对，与第一个交易对基础币相同，且计价币不同
				for j:=0;j<len(symbolsReturn.Data);j++  {
					switch symbolsReturn.Data[j].QuoteCurrency {
					case "usdt","husd","btc","eth":
					if symbolsReturn.Data[j].BaseCurrency== symbolsReturn.Data[step_1_count].BaseCurrency && j!=step_1_count{
						//step_2:=symbolsReturn.Data[j].Symbol
						step_2_count:=j
						//log.Println("=====",step_2,step_1)
						//获取套利第三步的交易对，取第一个交易对的计价币和第二个交易对的计价币，第三步交易对币种顺序无影响
						for k:=0 ;k<len(symbolsReturn.Data); k++ {
							if k!=step_2_count {
								step_1_symbol:=symbolsReturn.Data[step_1_count].QuoteCurrency+symbolsReturn.Data[step_2_count].QuoteCurrency
								step_2_symbol:=symbolsReturn.Data[step_2_count].QuoteCurrency+symbolsReturn.Data[step_1_count].QuoteCurrency
								switch symbolsReturn.Data[k].Symbol {
								case step_1_symbol,step_2_symbol:
									//log.Println("k.....",k)
									//step_3:=symbolsReturn.Data[k].Symbol
									//log.Println("step_3",step_1,step_2,step_3,"step_3_count",step_1_count,step_2_count,k)
									schedulingIndex.Step1Index=step_1_count
									schedulingIndex.Step2Index=step_2_count
									schedulingIndex.Step3Index=k
									schedulingIndexArg=append(schedulingIndexArg,schedulingIndex)
								}
							}
						}
					}
				}
				}
			}
		}
	}
	return schedulingIndexArg,symbolsReturn.Data
}
